package com.kaka.bus.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.kaka.bus.R;


/**
 * Created by zhangqi on 2016/10/25.
 */

public class InfoItemView extends FrameLayout {

    private TextView mInfo;
    private ImageView mIcon;
    private ImageView mYou;
    private TextView mTips;

    public InfoItemView(Context context) {
        this(context, null);
    }

    public InfoItemView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public InfoItemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setBackgroundResource(R.drawable.layout_ripple_white);
        setClickable(true);
        initView();

        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.InfoItemView);
        String info = a.getString(R.styleable.InfoItemView_item_info);
        int info_icon = a.getResourceId(R.styleable.InfoItemView_item_info_icon, -1);

        mInfo.setText(info);
        if (!(info_icon == -1)) {
            mIcon.setImageResource(info_icon);
        }

        a.recycle();
    }

    public void setTips(String tips) {
        mTips.setText(tips);
        mTips.setVisibility(VISIBLE);
    }

    private void initView() {
        View.inflate(getContext(), R.layout.item_info, this);

        mInfo = (TextView) findViewById(R.id.item_tv_info);
        mIcon = (ImageView) findViewById(R.id.item_iv_info_icon);
        mYou = (ImageView) findViewById(R.id.item_iv_info_you);
        mTips = (TextView) findViewById(R.id.item_iv_info_tips);
    }

    public ImageView getInfoYou() {
        if (mYou != null) {
            return mYou;
        } else {
            return null;
        }

    }

}
